def is_prime(n):
  if n <= 1:
    return False
  for i in range(2, int(n*0.5) + 1):
    if n % i == 0:
      return False
  return True
def max_prime(number_str):
  if len(number_str) != 4 or not number_str.isdigit():
    return 0
  max_prime = 0
  for i in range(4):
    for j in range(i + 1, 5):
      number = int(number_str[i:j])
      if is_prime(number) and number > max_prime:
        max_prime = number
  return max_prime
number_str = input()
print(max_prime(number_str))